# Maintainer: Gray Wolf <wolf@wolfsden.cz>
pkgname=bazel5
pkgver=5.3.2
pkgrel=0
pkgdesc="Bazel is an open-source build and test tool"
url="https://bazel.build/"
# 1. Copy arch line from openjdk11, since we depend on it
# 2. aarch64, ppc64le times out in CI, 1h is not enough
arch="all !x86 !armhf !armv7 !riscv64 !s390x !aarch64 !ppc64le"
license="Apache-2.0"
depends="bash openjdk11-jdk"
makedepends="linux-headers python3 unzip zip"
# Bazel binary is thin C++ client with zip file embedded into the binary,
# stripping breaks that: https://github.com/bazelbuild/bazel/issues/11842
options="!strip"
provides="bazel=$pkgver-r$pkgrel"
subpackages="$pkgname-bash-completion"
source="
	https://github.com/bazelbuild/bazel/releases/download/$pkgver/bazel-$pkgver-dist.zip
	0001-Do-not-use-prebuilt-binaries.patch
	0002-Prefer-local_jdk-instead-of-remote_jdk11.patch
	0003-Make-generate_bash_completion-compatible-with-busybo.patch
	0004-Use-nojdk-bazel-for-generating-the-bash-completion.patch
"
builddir="$srcdir/"

build() {
	EMBED_LABEL=$pkgver-$pkgrel \
	EXTRA_BAZEL_ARGS=--tool_java_runtime_version=local_jdk \
		./compile.sh

	./output/bazel build //scripts:bazel-complete.bash
	cp bazel-bin/scripts/bazel-complete.bash output/

	./output/bazel clean --expunge
}

check() {
	# shellcheck disable=SC2046
	./output/bazel build $(\
		./output/bazel query --noshow_progress '//examples/...' \
			| grep -vF \
				-e /android/ \
				-e /windows/ \
				-e :hello-error-prone \
	)
	./output/bazel test \
		//examples/cpp:hello-success_test \
		//examples/java-native/src/test/java/com/example/myproject:custom \
		//examples/java-native/src/test/java/com/example/myproject:hello \
		//examples/java-starlark/src/test/java/com/example/myproject:pass \
		//examples/py_native:test \
		//examples/shell:test

	./output/bazel clean --expunge
}

package() {
	install -Dm 755 -t "$pkgdir/usr/bin" output/bazel
	install -Dm 644 output/bazel-complete.bash \
		"$pkgdir/usr/share/bash-completion/completions/bazel"
}

sha512sums="
a63895c224d51619cf83e6e55872aa6d55d17c7dcea59eaf467069d2c95259f5964fbf8fa5994df0e3c030234a7adf70a2715edb4edbbe2bf69d21dd698c0833  bazel-5.3.2-dist.zip
5b7709629f1f4a4604abbf626c17b0a83f3ddcb8e71a05d253eb592e1006027d693d58d67d35deb941ed1e0e60fa8d1f3229b59f844fa7e3eca866cafc2354f2  0001-Do-not-use-prebuilt-binaries.patch
b5b6aeb5d8b097bd6f58d441f801dce9b3f2ed7706623d0c8650582a421509e4c843b6e298affeb3256dded4f706a56502847b391ec666ac882362d34529ad25  0002-Prefer-local_jdk-instead-of-remote_jdk11.patch
a422b45f90733157c14f3c4c54a88acd1ad49053b043a90a37c67e6d5342acb9685c467c642c232fc5cc6c80ec35a8187284da06d36e8084f0583e86e73a9130  0003-Make-generate_bash_completion-compatible-with-busybo.patch
fb51b7caf1b05c3f531bbbbdb4fe76666c07f423d66ab0826a0590f09b71e67197d46a36c307d1690845f8055c523c27f00a21e890b7457b402d68ba1a12b085  0004-Use-nojdk-bazel-for-generating-the-bash-completion.patch
"
